package com.study.homework;

public class Node {
    int data;
    Node next;

    public Node(int data) {
        this.data = data;
    }

    public static Node from(int[] a) {
        Node header = new Node(a[0]);
        Node temp = header;
        for (int i = 1; i < a.length; i++) {
            temp.next = new Node(a[i]);
            temp = temp.next;
        }
        return header;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        Node node = this;
        while (node != null) {
            sb.append(node.data)
                    .append(",");
            node = node.next;
        }
        return sb.toString();
    }
}
